home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Memphis Amiga Group / MAG Utilities 3 (1987-03)(Memphis Amiga Group)[Disk 038].zip / MAG Utilities 3 (1987-03)(Memphis Amiga Group)[Disk 038].adf / c / DevAvail.c < prev    next >
C/C++ Source or Header  |  1987-05-25  |  2KB  |  69 lines

  1. /* DevAvail by John V Pope 25 May '87
  2. /* 
  3. /* This program was inspired by a message I read recently on CompuServe(TM).
  4. /*   It is intend to allow for checking for the existence of a device so as
  5. /* to allow a startup-sequence file to determine whether or not to AddBuffers
  6. /* and such.
  7. /* 
  8. /* Usage: DevAvail <DEVICE>
  9. /*        Where DEVICE is any legal AmigaDOS device (or directory) name.
  10. /*
  11. /* Additionally the argument "?" and lack of any arguments prints out a usage
  12. /* banner.
  13. /* 
  14. /* The program will FAIL (return error 20) if the device does not exist.
  15. /* Therefore usage is the same as programs such as ASK and PAUSE.
  16. /* 
  17. /* Example:
  18. /*       Failat 25          ;Anything above 20 here is just fine.
  19. /*       DevAvail DF1:      ;Determine if DF1: is available 
  20. /*       If NOT ERROR       ;Checking for DevAvail return code...
  21. /*       AddBuffers DF1: 25 ;I can access that device now.
  22. /*       Endif
  23. /* 
  24. /* Permission is granted for unlimited use of any type whatsoever. Just leave
  25. /*  all credits atatched.
  26. */
  27.  
  28. #include <libraries/dosextens.h>
  29.  
  30. /* #define DEBUG
  31. */
  32.  
  33. #define BANNER "\nDevAvail by John V Pope 25 May 87.\
  34. \nUsage: DevAvail <DEVICE>\
  35. \n       Where DEVICE is any legal AmigaDOS device (or directory) name.\
  36. \nFail code 20 returns to Execute if not available."
  37.  
  38. #define FAIL 20   /* keeps from having to add another include */
  39.  
  40. main(argc,argv)
  41. int argc;
  42. char *argv[];
  43. {
  44. struct Process *pr;
  45.  
  46.    if(argc != 2 || !strcmp(argv[1],"?"))
  47.       {
  48.       puts(BANNER);
  49.       }else
  50.          {
  51.          pr=(struct Process *)FindTask(0L); /* Find me. */
  52.          pr->pr_WindowPtr = -1; /* No Dos requesters, please. */
  53. #ifdef DEBUG
  54.          puts(argv[1]);
  55. #endif
  56.          if(DeviceProc(argv[1])==NULL)
  57.             {
  58. #ifdef DEBUG
  59.             puts("Device Not Found.");
  60. #endif
  61.             exit(FAIL);     /* Couldn't find it so error is returned */
  62.             }
  63. #ifdef DEBUG
  64.              else
  65.                puts("Device exists.");
  66. #endif
  67.          }
  68. }/* Just fall off the end of the world to indicate a device exists */
  69.